package com.briup.day22;

/**
 * @author ThinkBook
 */
public class Test07_Name {
    //获取线程默认名称 Thread-n[0,1...]
    public static void main(String[] args) {
        //如何获取主线程对象？主线程的名字是什么？
        Thread mainTh = Thread.currentThread();
        System.out.println("主线程: " + mainTh.getName());

        System.out.println("--------------");

        //1.创建子线程
        Thread th1 = new Thread() {
            @Override
            public void run() {
                //
                String name = Thread.currentThread().getName();
                System.out.println("in th1 run,name: " + name);
            }
        };

        th1.start();

        Thread th2 = new Thread();
        System.out.println("th2.name: " + th2.getName());

        // 哪个线程执行 currentThread()，返回的就是哪个线程
        Thread th = th2.currentThread();
        System.out.println("th.name: " + th.getName());

    }
}
